<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Perfis Candidato</title>
<style>
	.container { border:2px solid #ccc; width:300px; height: 150px; overflow-y: scroll; }
</style>
</head>

<body>
<?php 
	include 'includes/conectionMySql.inc';
	// variável de Conexão = $db;
	$id = $_GET['id'];
?>

<form method="post" action="atualizarPerfil.php?id=<?php echo $id;?>">
	<h4>Perfis do Candidato</h4>
    <div class="container">
    <input type="checkbox" id="chkPerfil" name="chkPerfil[]" value='-1' 
	<?php 
		$query = "SELECT count(*) as count FROM topoffice_perfil_pessoa pp where pp.id_pessoa = $id";
		$result = mysql_query($query);
		$qtd = mysql_fetch_array($result,MYSQL_ASSOC);
		$qtds = $qtd['count'];
		echo ($qtds>0)?'':' checked="checked" ';
	?>/>Sem Perfil<br />
    <input type="checkbox" id="chkPergil" name="chkPerfil[]" value='0'<?php 
	$query = "SELECT count(*) as count FROM topoffice_perfil_pessoa pp WHERE id_pessoa = $id and id_cliente_perfil = 0";
	$aux = mysql_query($query);
	$desistente = mysql_fetch_array($aux,MYSQL_ASSOC);
	$des = $desistente['count'];
	echo ($des>0)?' checked=/"checked/" ':'';	
	?>/>Desistente<br />
    <? 
		$query = "SELECT  a.id as id_cliente, a.nome as nome_cliente FROM sgi_cliente a order by nome_cliente asc";
		$result = mysql_query($query) or die("Não foi possível executar a Query.".mysql_error());
		while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
			$id_cliente = $row['id_cliente'];
			$nome_cliente = $row['nome_cliente'];
		?>
        	<input type="checkbox" id="chkPerfil" name="chkPerfil[]" <?php 
			$sqlAux = "select count(*) as count from topoffice_perfil_pessoa pp where pp.id_pessoa = $id and pp.id_cliente_perfil = $id_cliente"; 
			$aux = mysql_query($sqlAux);
			$aux1 = mysql_fetch_array($aux,MYSQL_ASSOC);
			$aux2 = $aux1['count'];
			echo ($aux2>0)?' checked="checked" ':'';?>value="<? echo $id_cliente;?>"/><? echo $nome_cliente;?><br />
	<? 			
		}	
	?>    
    </div>
    <input type="submit" value="Atualizar"/>
</form>
<?php 
	mysql_close($db);
?>
</body>
</html>